package com.cookor.poi.modules.phy.web;

import com.cookor.poi.common.config.Global;
import com.cookor.poi.common.persistence.Page;
import com.cookor.poi.common.utils.StringUtils;
import com.cookor.poi.common.web.BaseController;
import com.cookor.poi.modules.phy.entity.TEvaluate;
import com.cookor.poi.modules.phy.service.TEvaluateService;
import com.cookor.poi.modules.sys.utils.UserUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
@RequestMapping({"${adminPath}/phy/tEvaluate"})
public class TEvaluateController extends BaseController {
  @Autowired
  private TEvaluateService tEvaluateService;
  
  @ModelAttribute
  public TEvaluate get(@RequestParam(required = false) String id) {
    TEvaluate entity = null;
    if (StringUtils.isNotBlank(id))
      entity = this.tEvaluateService.get(id); 
    if (entity == null)
      entity = new TEvaluate(); 
    return entity;
  }
  
  @RequiresPermissions({"phy:tEvaluate:view"})
  @RequestMapping({"list", ""})
  public String list(TEvaluate tEvaluate, HttpServletRequest request, HttpServletResponse response, Model model) {
    tEvaluate.setTenantId(UserUtils.getTenantId());
    Page<TEvaluate> page = this.tEvaluateService.findPage(new Page(request, response), tEvaluate);
    model.addAttribute("page", page);
    model.addAttribute("tEvaluate", tEvaluate);
    return "modules/phy/tEvaluateList";
  }
  
  @RequiresPermissions({"phy:tEvaluate:view"})
  @RequestMapping({"form"})
  public String form(TEvaluate tEvaluate, Model model) {
    model.addAttribute("tEvaluate", tEvaluate);
    return "modules/phy/tEvaluateForm";
  }
  
  @RequiresPermissions({"phy:tEvaluate:edit"})
  @RequestMapping({"save"})
  public String save(TEvaluate tEvaluate, Model model, RedirectAttributes redirectAttributes) {
    if (!beanValidator(model, tEvaluate, new Class[0]))
      return form(tEvaluate, model); 
    this.tEvaluateService.save(tEvaluate);
    addMessage(redirectAttributes, new String[] { "保存评价成功" });
    return "redirect:" + Global.getAdminPath() + "/phy/tEvaluate/?repage";
  }
  
  @RequiresPermissions({"phy:tEvaluate:edit"})
  @RequestMapping({"delete"})
  public String delete(TEvaluate tEvaluate, RedirectAttributes redirectAttributes) {
    this.tEvaluateService.delete(tEvaluate);
    addMessage(redirectAttributes, new String[] { "删除评价成功" });
    return "redirect:" + Global.getAdminPath() + "/phy/tEvaluate/?repage";
  }
}
